//
//  DelGoodsCollectVm.swift
//  Pods
//
//  Created by eme on 2017/3/30.
//
//

import RxSwift
import SwiftyJSON
import NetWorkCore
import ModelProtocol
import RickonCore

class DelGoodsCollectVm {
    
    let setGoodsCollect = PublishSubject<String>()
    
    let backDate = Variable<[CollectGoodsListModel]>([])
    
    let disposeBag = DisposeBag()
    
    let error = PublishSubject<MikerError>()
    
    let refreshing = Variable(false)
    
    var page = 0
    
//    var length = PAGESIZE
    
    init (){
        
        let request = setGoodsCollect.map{ cid in
            
            return MineApi.deleteGoodsCollect(cid: cid,page:0,length: AppConfig.pageSize)
            
            }.shareReplay(1)
        
        let response = request.emeRequestApiForArray(CollectGoodsListModel.self).shareReplay(1)
        
        response.subscribe(onNext:{[unowned self] result in
            
            switch result{
                
            case .success(let data):
                
                self.backDate.value = data
                
            case.failure(let error):
                
                self.error.onNext(error)
                
            }
            
        }).addDisposableTo(disposeBag)
    }
    
}
